﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SaturniLibrary.Cache
{
    public class CachePolicyManager
    {
        private static Dictionary<string, CachePolicy> cachePolicyList = new Dictionary<string, CachePolicy>(StringComparer.OrdinalIgnoreCase);
        //public static Dictionary<string, CachePolicy> CachePolicyList { get { return cachePolicyList; } }

        public static CachePolicy Get(string groupName)
        {
            if (cachePolicyList.ContainsKey(groupName))
            {
                return cachePolicyList[groupName];
            }
            CachePolicy cachePolicy = new CachePolicy();
            cachePolicy.PolicyName = "default";
            cachePolicy.ExpiredSeconds = 24 * 60 * 60;
            return cachePolicy;
        }

        public static void Set(CachePolicy cachePolicy)
        {
            Set(cachePolicy.PolicyName, cachePolicy);
        }

        public static void Set(string groupName, CachePolicy cachePolicy)
        {
            if (cachePolicyList.ContainsKey(groupName))
            {
                cachePolicyList[groupName] = cachePolicy; ;
            }
            else
            {
                cachePolicyList.Add(groupName, cachePolicy);
            }
        }
    }
}
